﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;

namespace BCNPCObject
{
    public class cls_PC1_BCKD_4B_Controller
    {
         #region   Atributes

        private DataSet CMIS_Header = new CMISOutputParameter();
        private DataSet ds = new DataSet();
        private DataTable dt = new DataTable();
        private PC1_BCKD4B info;

        #endregion

        #region   Constructor

        public cls_PC1_BCKD_4B_Controller()
        {
            info = new PC1_BCKD4B();
        }
        public cls_PC1_BCKD_4B_Controller(PC1_BCKD4B Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public PC1_BCKD4B pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region  BCKD NPC

        public IEnumerable<PC1_BCKD4B> select_Data_BCKD16(System.String pr_MA_DVIQLY, System.Int16 intNam, System.Int16 intThang)
        {
            var a = from p in CMIS2.DB.PC1_BCKD4B
                    where p.MA_DVIQLY == pr_MA_DVIQLY
                    && p.NAM == intNam
                    && p.THANG == intThang
                    orderby p.STT ascending
                    select p;
            if (a != null && a.Count() > 0)
            {
                return a;
            }
            else
                return null;
        }

        public IEnumerable<PC1_BCKD4B> select_PC1_BCKD4B_411(string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                CMIS2.ResetDB();
                string maso = "41";
                //var q = from p in CMIS2.DB.PC1_BCKD4B
                //        orderby p.MA_SO, p.MA_DVIQLY ascending
                //        where (p.MA_DVIQLY == strMadviqly) && (p.THANG == strThang) && (p.NAM == strNam)
                //        select p;
                //return q;

                var k = from m in CMIS2.DB.PC1_BCKD4B
                        orderby m.MA_DVIQLY ascending
                        where (m.MA_DVIQLY.Contains(strMadviqly)) && (m.MA_DVIQLY != strMadviqly) && (m.MA_SO.Contains(maso)) && (!m.MA_SO.Contains("0")) && (!m.MA_SO.Contains("T"))
                                && (m.THANG == strThang)
                                && (m.NAM == strNam)
                        select m;
                


                if (k != null && k.Count() > 0)
                {

                    return k;
                }
                else
                    return null;

            }
            catch (Exception ex)
            {
                CMIS2.ResetDB();
                return null;
            }
        }


        public IEnumerable<PC1_BCKD4B> select_PC1_BCKD4B(string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                CMIS2.ResetDB();
                string maso = "41";
                 var q = from p in CMIS2.DB.PC1_BCKD4B
                            orderby p.MA_SO, p.MA_DVIQLY ascending
                            where (p.MA_DVIQLY == strMadviqly) && (p.THANG == strThang) && (p.NAM == strNam)
                            select p;
                    return q;

                    //var k = from m in CMIS2.DB.PC1_BCKD4B
                    //        orderby m.MA_SO, m.MA_DVIQLY ascending
                    //        where (m.MA_DVIQLY.Contains(strMadviqly)) && (m.MA_DVIQLY != strMadviqly) && (m.MA_SO.Contains(maso)) && (!m.MA_SO.Contains("0")) && (!m.MA_SO.Contains("T"))
                    //        select m;

                    //var s = from n in q
                    //        from nn in k
                    //        select;


                    if (q != null && q.Count() > 0)
                    {

                        return q;
                    }
                    else
                        return null;
               

            }
            catch (Exception ex)
            {
                CMIS2.ResetDB();
                return null;
            }
        }

        #endregion
    }
}
